<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!--左侧导航-->
<aside class="lyear-layout-sidebar">
	
	<!-- logo -->
	<div id="logo" class="sidebar-header">
		<a href="index.html"><img src="images/logo-sidebar.png" title="LightYear" alt="LightYear" /></a>
	</div>
	<div class="lyear-layout-sidebar-scroll">
		
		<nav class="sidebar-main">
			<ul class="nav nav-drawer">
				<li class="nav-item active"> <a href="admin/toIndex"><i class="mdi mdi-home"></i> 后台首页</a> </li>
				<li class="nav-item nav-item-has-subnav">
					<a href="javascript:void(0)"><i class="mdi mdi-account-box"></i> 员工管理</a>
					<ul class="nav nav-subnav">
						<li> <a href="admin/toEmployee">人员管理</a> </li>
						<li> <a href="admin/toDepartment">部门管理</a> </li>
					</ul>
				</li>
			</ul>
		</nav>
		
		<div class="sidebar-footer">
			<p class="copyright">Copyright &copy; 2019. <a target="_blank" href="http://lyear.itshubao.com">IT书包</a> All rights reserved.</p>
		</div>
	</div>

</aside>
<!--End 左侧导航-->

<!--头部信息-->
<header class="lyear-layout-header">
	
	<nav class="navbar navbar-default">
		<div class="topbar">
			
			<div class="topbar-left">
				<div class="lyear-aside-toggler">
					<span class="lyear-toggler-bar"></span>
					<span class="lyear-toggler-bar"></span>
					<span class="lyear-toggler-bar"></span>
				</div>
				<span class="navbar-page-title"> 后台首页 </span>
			</div>
			
			<ul class="topbar-right">
				<li class="dropdown dropdown-profile">
					<a href="javascript:void(0)" data-toggle="dropdown">
						<span id="usernameSpan"> <span class="caret"></span></span>
					</a>
					<ul class="dropdown-menu dropdown-menu-right">
						<li> <a onclick="showupdatePwd()"><i class="mdi mdi-lock-outline"></i> 修改密码</a> </li>
						<li class="divider"></li>
						<li> <a href="logout"><i class="mdi mdi-logout-variant"></i> 退出登录</a> </li>
					</ul>
				</li>
			</ul>

		</div>
	</nav>

</header>
<!--End 头部信息-->

<!-- 修改密码模态框 -->
<div class="modal fade" id="updatePwdModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true"></span></button>
				<h4 class="modal-title">修改密码</h4>
			</div>
			<div class="modal-body">
				<form id="updatePwdForm" class="form-horizontal" action="#" method="post" onsubmit="return false;">
					<input type="hidden" id="usernameUpdate" />
					<div class="form-group">
						<label class="col-md-3 control-label" for="newPwd">新密码</label>
						<div class="col-md-7">
							<input class="form-control" type="password" id="newPwd" onkeyup="checkpassword()" placeholder="请输入新密码">
						</div>
					</div>
					<div class="form-group">
						<label class="col-md-3 control-label" for="againPwd">重复新密码</label>
						<div class="col-md-7">
							<input class="form-control" type="password" id="againPwd" onkeyup="checkpassword()" placeholder="请输入重复新密码">
							<span id="tishi"></span>
						</div>
					</div>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default btn-sm" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary btn-sm" id="submit" disabled onclick="updatePwd()">修改</button>
			</div>
		</div>
	</div>
</div>
<!-- End 修改密码模态框 -->

<script type="text/javascript" src="js/jquery.min.js"></script>
<!--消息提示-->
<script src="js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="js/lightyear.js"></script>

<%--通过ajax获取已登录用户信息--%>
<script>
	$(function () {
		$.ajax({
			url: "getLoginInfo",
			type: "GET",
			dataType: "JSON",
			success: function (resp) {
				$("#usernameSpan").text(resp.data.username);
			}
		})
	})
</script>

<script>
	//验证两次密码是否一致
	function checkpassword() {
		var password = document.getElementById("newPwd").value;
		var repassword = document.getElementById("againPwd").value;

		if(password == repassword ) {
			if (password != "" ){
				document.getElementById("tishi").innerHTML="<br><font color='green'>两次密码输入一致</font>";
				document.getElementById("submit").disabled = false;
			}else {
				document.getElementById("tishi").innerHTML="<br><font color='red'>密码不能为空!</font>";
				document.getElementById("submit").disabled = true;
			}
		}else {
			document.getElementById("tishi").innerHTML="<br><font color='red'>两次输入密码不一致!</font>";
			document.getElementById("submit").disabled = true;
		}
	}

	function showupdatePwd(){
		$("#updatePwdModal").modal('show');
	}
	function updatePwd(){
		lightyear.loading('show');
		$.ajax({
			url: "updatePwd",
			type: "POST",
			data:{password:$("#newPwd").val()},
			dataType: "JSON",
			success: (resp) => {

				lightyear.loading('hide');
				lightyear.notify('修改成功', 'success', 900, 'mdi mdi-emoticon-happy', 'top', 'center');
				//隐藏模态框
				$("#updatePwdModal").modal('hide');
				//清空模态框
				$("#updatePwdForm")[0].reset();

				//一秒后退出登录
				setTimeout(function (){
					window.location.href="logout";
				}, 1000);
			}
		})
	}
</script>